Server-side code (main.asc):
============================

load( "NetServices.asc" );

//This will get called when the application first starts
application.onAppStart = function()
{
	trace("onAppStart called");

	NetServices.setDefaultGatewayUrl("http://localhost:8500/flashservices/gateway");
	gatewayConn = NetServices.createGatewayConnection();
	getlinks_cfc = gatewayConn.getService("cfdocs.myapp.getlinks", this);

	this.so = SharedObject.get("links",true);

	this.interval = setInterval(getData,1000);
}

//Prevent Garbage Collection from unloading this application
application.onAppStop = function()
{ 
	trace("onAppStop Called, returning false");
	return false;
}

function getData()
{
	getlinks_cfc.getAllLinks();
}

application.getAllLinks_Result = function(val)
{
	clearInterval(this.interval);
	this.interval = setInterval(getData,60000);	//get results every minute
	
	trace("Result:"+val.getLength());

	this.so.lock();

	//Loop through the results
	for (var i=0; i<val.getLength(); i++) {

		//Remove definitions introduced by NetServices.asc
		val.items[i].unshift = null;
		val.items[i].registerClass = null;
		val.items[i].__ID__ = null;

		//Get local copy of the current link
		var oldObj = application.so.getProperty(i);

		var dirty = false;

		if (oldObj == null)
			dirty = true; // The slot is new
		else {
			for (var j in oldObj) {
				// loop through the fields of the saved object

				if (oldObj[j] != val.items[i][j]) {
					//A field is different than its saved copy
					dirty = true;
					break;
				}
			}
		}

		if (dirty) {
			trace("Slot "+i+" is dirty");
			this.so.setProperty(i, val.items[i]);	//Saving in the shared object
		}
	}

	this.so.unlock();
}


Client-side code:
=================

nc = new NetConnection();
nc.onStatus = function(info)
{
	trace(info.code);
	so.connect(this);
}

nc.connect("rtmp://myFlashComServerDomain.com/myApp");

so = SharedObject.getRemote("links",nc.uri,"/");

so.onSync = function(list)
{
	trace("onSync:");
	for (i in list)
		trace(i+":"+list[i].name+","+list[i].code);

	updateList();
}

function updateList()
{
	links_lb.removeAll();
	for (var i in so.data) {
		links_lb.addItem(so.data[i].link);
	}
}

CFC Code:
=========

<cfcomponent> 

  <cffunction name="getAllLinks" access="remote" returnType="query">  

    <cfquery name="Links" dataSource="my_db">

      select *
      from	links

    </cfquery>

    <cfreturn Links>

  < /cffunction>

< /cfcomponent>

